package com.moorror.codegenvel.utils;

import com.intellij.openapi.project.Project;
import com.moorror.codegenvel.common.dialog.MRDialogInputName;
import com.moorror.codegenvel.db.sqlite.dao.BaseDAO;
import com.moorror.codegenvel.db.sqlite.dao.impl.CommonHistoryDaoImpl;
import com.moorror.codegenvel.db.sqlite.entity.AbEntity;
import com.moorror.codegenvel.db.sqlite.entity.CommonHistory;
import org.apache.commons.lang3.tuple.Pair;

/**
 * @Author jiyanghuang
 * @Date 2025/11/2 17:14
 */
public class HistoryTableUtils {

    public static void sceneAdd(Project project, String type, String jsonValue){
        new MRDialogInputName("", "New History Key Name", project, (form) -> {
            CommonHistory history = AbEntity.of(CommonHistory.class);
            history.setScene(form.getInputName().getText());
            history.setKf(type);
            history.setExtColumnJson(jsonValue);
            return BaseDAO.checkExistAdd(history, CommonHistoryDaoImpl.getInstance(), CommonHistory::getScene, () -> {
                return Pair.of(true, null);
            });
        }).ofDialogShow();
    }
}
